import java.util.concurrent.Callable;

public class Test {
    public static void main(String[] args) throws Exception {
        CallableClass c = new CallableClass();
        // 直接调用报错
        // runRunnable(c);
        // 通过适配器转换
        runRunnable(new RunnableAdapter(c));
    }

    public static void runRunnable(Runnable r) {
        r.run();
    }
}

// 将一个类的接口转换成客户希望的另外一个接口，使得原本由于接口不兼容而不能一起工作的那些类可以一起工作。
class CallableClass implements Callable<Integer> {
    @Override
    public Integer call() {
        System.out.println("CallableClass is runing");
        return 0;
    }
}

class RunnableAdapter implements Runnable {
    Callable<?> c;

    RunnableAdapter(Callable<?> c1) {
        c = c1;
    }

    @Override
    public void run() {
        try {
            c.call();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}